package com.example.studentmanager.controller;


import com.example.studentmanager.model.Student;
import com.example.studentmanager.model.Teacher;
import com.example.studentmanager.service.StudentService;
import com.example.studentmanager.service.TeacherService;
import com.example.studentmanager.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
@RequestMapping("teacher")
public class TeacherController {


    @Autowired
    TeacherService teacherService;

    @RequestMapping("setProportion")
    public String setProportion( String usual, String middle,String fina){
        System.out.println("平时成绩："+usual);
        return "";
    }





    @RequestMapping(value = "seaTea")
    public String searchTeacher(ModelMap modelMap){

        return "";

    }


    @RequestMapping("changeTea")
    public String changeTea(HttpSession session, Teacher teacher){
        teacherService.updateTeacher(teacher);
        teacher=teacherService.searchTeacher(teacher.getTeaid());
        session.setAttribute("teacher",teacher);
        return "back/teacher/userInformation";
    }


    @RequestMapping("findAll")
    public String searchAll(Integer page,String searchCol,String searchValue,Model model){

        //1.获取用户查询的当前页
        page=page==null?1:page;
        //2.获取每页显示的条数
        Integer rows=2;

        //获取用户输入的条件
        System.out.println(searchCol+"----"+searchValue);
        //调用业务层
        //3.求每页显示的成绩列表
        List<Teacher> teachers = teacherService.searchAll(page,rows,searchCol,searchValue);
        //4.总记录数
        Integer counts =teacherService.counts(searchCol, searchValue);
        //5.总页数
        Integer pages=counts%rows==0?counts/rows:counts/rows+1;
        //2.设置在域中

        model.addAttribute("page", page);
        model.addAttribute("pages", pages);
        model.addAttribute("counts", counts);
        model.addAttribute("searchCol",searchCol);
        model.addAttribute("searchValue",searchValue);
        //3.转发到前端页面
        model.addAttribute("teachers",teacherService.searchAll(page,rows,searchCol,searchValue));
        return "back/teacher/index";

    }

}
